var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var prefix = 'h5_pf_';
var rules = {
    address: [
        { required: true, message: '请输入地址', trigger: 'blur' },
    ],
    usdtplace: [
        { required: true, message: '请输入USDT地址', trigger: 'blur' },
    ],
    title: [
        { required: true, message: '请输入标题', trigger: 'blur' },
    ],
    contents: [
        { required: true, message: '请输入内容', trigger: 'blur' },
    ],
    connect: [
        { required: true, message: '请输入联系方式', trigger: 'blur' },
    ],
    account: [
        { required: true, message: '请输入账号', trigger: 'blur' },
    ],
    mobile: [
        { required: true, message: '请输入手机号', trigger: 'blur' },
        { pattern: /^[1]([3-9])[0-9]{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
    ],
    captcha: [
        { required: true, message: '请输入验证码', trigger: 'blur' },
    ],
    username: [
        { required: true, message: '请输入用户名', trigger: 'blur' },
    ],
    oldpassword: [
        { required: true, message: '请输入旧密码', trigger: 'blur' },
    ],
    newpassword: [
        { required: true, message: '请输入新密码', trigger: 'blur' },
    ],
    newpassword_b: [
        { required: true, message: '请输入确认新密码', trigger: 'blur' },
    ],
    password: [
        { required: true, message: '请输入密码', trigger: 'blur' },
    ],
    tjcode: [
        { required: true, message: '请输入推荐人账号', trigger: 'blur' },
    ],
    paypwd: [
        { required: true, message: '请输入支付密码', trigger: 'blur' },
        { len: 6, message: '请输入6位支付密码', trigger: 'blur' },
    ],
    paypwd_b: [
        { required: true, message: '请确认支付密码', trigger: 'blur' },
    ],
    newpaypwd: [
        { required: true, message: '请输入支付密码', trigger: 'blur' },
        { len: 6, message: '请输入6位支付密码', trigger: 'blur' },
    ],
    newpaypwd_b: [
        { required: true, message: '请确认支付密码', trigger: 'blur' },
    ],
    resource: [
        { required: true, message: '请选择活动资源', trigger: 'change' }
    ],
    desc: [
        { required: true, message: '请填写活动形式', trigger: 'blur' }
    ]
};
var $http = {
    get: function (url, params) {
        if (params === void 0) { params = {}; }
        return __awaiter(this, void 0, void 0, function () {
            var res;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, axios.get(url, { params: params }).catch(function (error) {
                            console.log(error.response);
                            if (error.response.status === 401) {
                                window.location.href = './login.html';
                            }
                        })];
                    case 1:
                        res = _a.sent();
                        return [2 /*return*/, res];
                }
            });
        });
    },
    post: function (url, params) {
        return __awaiter(this, void 0, void 0, function () {
            var config, res;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        config = {
                            headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' }
                        };
                        return [4 /*yield*/, axios.post(url, Qs.stringify(params, { allowDots: true }), config).catch(function (error) {
                                if (error.response.status === 401) {
                                    window.location.href = './login.html';
                                }
                            })];
                    case 1:
                        res = _a.sent();
                        return [2 /*return*/, res];
                }
            });
        });
    },
    upload: function (url, formData) {
        return __awaiter(this, void 0, void 0, function () {
            var config, res;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        config = {
                            headers: { 'Content-Type': 'multipart/form-data;' }
                        };
                        return [4 /*yield*/, axios.post(url, formData, config)];
                    case 1:
                        res = _a.sent();
                        return [2 /*return*/, res];
                }
            });
        });
    }
};
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //判断是否是 android终端
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //判断是否是 iOS终端  
var isSend = false;
var $utils = {
    isAndroid: isAndroid,
    isIOS: isIOS,
    // 获取验证码
    getLocalStorage: function (key) {
        return localStorage.getItem(prefix + key);
    },
    setLocalStorage: function (key, value) {
        return localStorage.setItem(prefix + key, value);
    },
    query: function (params) {
        var search = location.search.slice(1);
        var obj = Qs.parse(search);
        return obj[params];
    },
    drawPic: function (container, canvas) {
        /**生成一个随机数**/
        function randomNum(min, max) {
            return Math.floor(Math.random() * (max - min) + min);
        }
        var code = ''; //首先默认code为空字符串
        if (!canvas) {
            $('body').append('<canvas style="display:none" id="canvas" width="106" height="41"></canvas>');
            canvas = document.getElementById("canvas");
        }
        var width = canvas.width;
        var height = canvas.height;
        var ctx = canvas.getContext('2d');
        ctx.textBaseline = 'bottom';
        canvas.style.display = 'none';
        ctx.clearRect(0, 0, width, height);
        /**绘制背景色**/
        ctx.fillStyle = '#fff';
        ctx.fillRect(0, 0, width, height);
        /**绘制文字**/
        var str = '0123456789';
        for (var i = 0; i < 4; i++) {
            var txt = str[randomNum(0, str.length)];
            ctx.fillStyle = "#0007F6"; // 字体颜色
            ctx.font = 'bold 28px MicrosoftYaHei'; // 字体大小
            var x = 15 + i * 17;
            var y = randomNum(35, 40);
            var deg = randomNum(-10, 10);
            //修改坐标原点
            ctx.translate(x, y);
            ctx.rotate(deg * Math.PI / 180);
            ctx.fillText(txt, 0, 0);
            //恢复坐标原点和旋转角度
            ctx.rotate(-deg * Math.PI / 180);
            ctx.translate(-x, -y);
            code = code + txt;
        }
        ;
        //新建Image对象，将canvas转换为base64添加到image的src属性上
        var img = new Image();
        img.onload = function () { ctx.drawImage(img, 0, 0); };
        img.src = canvas.toDataURL('image/jpg');
        //添加到body中
        container.html(img);
        return code;
    },
    showMsg: function (content, callback) {
        if (content === void 0) { content = ''; }
        return layer && layer.open({
            content: content,
            skin: 'msg',
            time: 2,
            success: function () {
                callback && setTimeout(callback, 2000);
            }
        });
    },
    sendSms: function ($el) {
        if (isSend) {
            return isSend;
        }
        isSend = true;
        var text = $el.text();
        var i = 60;
        $el.text(i + 's');
        var timer = setInterval(function () {
            i--;
            $el.text(i + 's');
            if (i === 0) {
                clearInterval(timer);
                $el.text(text);
                isSend = false;
            }
        }, 1000);
    },
    getPathElement: function (e, className) {
        for (var _i = 0, _a = e.path; _i < _a.length; _i++) {
            var item = _a[_i];
            if (item.className === className) {
                return item;
            }
        }
    }
};
